<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
    <style>
      #box {
        width: 200px;
        border: 1px solid lightcoral;
      }
    </style>
  </head>
  <body>
    <div>
      resize 事件触发次数
      <span>0</span>
    </div>

    <hr />
    <div id="box">元素resize</div>
    <button id="btn">修改元素尺寸</button>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script>
      $(function () {
        var x = 0
        $(window).resize(function () {
          $('span').text((x += 1))
        })

        // 元素 resize
        $('#box').resize(function () {
          console.log('元素 resize')
        })

        $('#btn').click(function () {
          var w = $('#box').width()
          console.log('w?', w)
          $('#box').width(w + 100)
        })
      })
    </script>
  </body>
</html>
